package com.yhf.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhf.dto.BranchDto;
import com.yhf.dto.ProjectOv;
import com.yhf.model.Branch;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

@Mapper
public interface BranchMapper extends BaseMapper<Branch> {
    @Results(id = "branchbto",value = {
            @Result(column = "bid",property = "bid"),
            @Result(column = "bname",property = "bname"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "status",property = "status"),
            @Result(column = "pid",property = "pid"),
            @Result(column = "pid",property = "projectOv",javaType = ProjectOv.class,one =
            @One(select = "com.yhf.mapper.PMapper.selectByPid",fetchType = FetchType.EAGER))
    })
    @Select("select * from branch ${ew.customSqlSegment}")
    IPage<BranchDto> selectAll(Page<BranchDto> page, @Param(Constants.WRAPPER) QueryWrapper<BranchDto> queryWrapper);

    @ResultMap("branchbto")
    @Select("Select * from branch where bid = #{bid}")
    BranchDto selectByBid(@Param("bid") String bid);
}
